package com.jack.leetcode.每日一题;

public class 把数字转成字符串 {

    public static void main(String[] args) {
        int num = 12258;
        System.out.println(translateNum(num));
        num = 506;
        System.out.println(translateNum(num));
    }

    public static int translateNum(int num) {
        String origin = num + "";
        int n = origin.length();
        int[] f = new int[n + 1];
        f[0] = 1;
        f[1] = 1;
        for (int i = 2; i < n + 1; i++) {
            if (origin.charAt(i - 2) - '0' != 0 && Integer.valueOf(origin.substring(i - 2, i)) < 26) {
                f[i] = f[i - 1] + f[i - 2];
            } else {
                f[i] = f[i - 1];
            }
        }
        return f[n];
    }
}
